package com.dx.chat.client;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import lombok.extern.slf4j.Slf4j;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * Description: 客户端controller
 *
 * @author rockstarsteve
 * @version 1.0
 * @copyright Copyright (c) 电信
 * @since 2023/9/8
 */
@Slf4j
public class ClientController implements Initializable {

    private ClientInfoBean clientInfoBean = new ClientInfoBean();

    private ClientService clientService = new ClientService();

    @FXML
    private TextField ip;
    @FXML
    private TextField port;
    @FXML
    private TextArea chatInfo;
    @FXML
    private TextField filePath;
    @FXML
    private TextField sendMsg;
    @FXML
    private BorderPane body;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        chatInfo.setEditable(false);
        //绑定内容
        ip.textProperty().bindBidirectional(clientInfoBean.ipProperty());
        port.textProperty().bindBidirectional(clientInfoBean.portProperty());
        chatInfo.textProperty().bindBidirectional(clientInfoBean.chatInfoStringProperty());
        filePath.textProperty().bindBidirectional(clientInfoBean.filePathProperty());
        sendMsg.textProperty().bindBidirectional(clientInfoBean.sendMsgProperty());
    }

    public void connection(ActionEvent actionEvent) {
        clientService.connection(clientInfoBean);
    }

    public void sendFile(ActionEvent actionEvent) {
        clientService.sendFile(clientInfoBean);
    }

    public void sendMsg(ActionEvent actionEvent) {
        clientService.sendMsg(clientInfoBean);
    }

    public void chooseFile(MouseEvent mouseEvent) {
        clientService.chooseFile(clientInfoBean, body);
    }
}
